package com.vf.s.mvc.city.controller;

import com.jfinal.aop.Before;
import com.jfinal.aop.Inject;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.tx.Tx;
import com.vf.core.controller.BaseController;
import com.vf.s.common.model.city.BizCity;
import com.vf.s.common.model.city.BizCityMenu;
import com.vf.s.mvc.city.service.BizCityService;
public class BizCityContoller  extends BaseController{
	
	
	@Inject
	private BizCityService bizCityService;
	
	public void index() {
		render("list.html");
	}
	
	public void editor() {
		this.setAttr("city", bizCityService.findById(this));
		render("editor.html");
	}
	
	public void setting() {
		this.setAttr("city", bizCityService.findById(this));
		render("setting.html");
	}
	
	public void listData() {
		Page<BizCity> page=bizCityService.listData(this);
		renderLayuiPage(0, page.getList(), "", page.getTotalRow());
	}
	
	public void save() {
		renderJson(bizCityService.save(this));
	}

	/***
	 * 删除
	 * 
	 * @throws Exception
	 */
	@Before(Tx.class)
	public void delete() throws Exception {
		String id = getPara("id");
		BizCity model = BizCity.dao.findById(id);
		if (model != null) {
			if (model.delete()) {
				Db.delete("DELETE FROM " + BizCityMenu.TABLE_NAME + " WHERE CITYID=? ", id);
				renderSuccess("删除成功！");
			} else {
				renderError("删除失败！");
			}
		} else {
			renderError("数据不存在,请刷新后再试!");
		}
	}
	
	
	public void findById() throws Exception {
		BizCity model = bizCityService.findById(this);
		if (model != null) {
			renderSuccess("成功！",model);
		} else {
			renderError("数据不存在,请刷新后再试!");
		}
	}

}
